package com.uduew.sjd.view.xpop;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.uduew.sjd.R;
import com.uduew.sjd.api.AppUpdateApi;
import com.lxj.xpopup.core.CenterPopupView;

public class UpdatePromptXpop extends CenterPopupView implements View.OnClickListener {
    TextView mGoUpdateContentTv,
            mCancelTv;
    AppUpdateApi.AppUpdateBean bean;
    private TextView tvContent;
    private TextView tvVersion;
    private Context context;

    public UpdatePromptXpop(@NonNull Context context, AppUpdateApi.AppUpdateBean bean) {
        super(context);
        this.bean = bean;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.xpop_updateprompt;
    }


    @Override
    protected void onCreate() {
        super.onCreate();
        tvContent = findViewById(R.id.xpop_updateprompt_content_tv);
        tvVersion = findViewById(R.id.version_num_tv);
        mGoUpdateContentTv = findViewById(R.id.xpop_goupdate_content_tv);
        mGoUpdateContentTv.setOnClickListener(this);
        mCancelTv = findViewById(R.id.xpop_updateprompt_cancel_tv);
        mCancelTv.setOnClickListener(this);
        tvContent.setText(bean.getUlcerogenic());
        tvVersion.setText(bean.getAllochthonous());
        if (bean.isDeorbit()) {
            mCancelTv.setVisibility(View.GONE);
        }
    }

    private OnAgreeClickListener onAgreeClickListener;

    public void setOnAgreeClickListener(OnAgreeClickListener listener) {
        this.onAgreeClickListener = listener;
    }

    public interface OnAgreeClickListener {
        void onAgreeClick(String url);

        void onCancelClick(Boolean isDeorbit);
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.xpop_goupdate_content_tv) {
            if (!bean.isDeorbit()) {
//                dismiss();
            }
            if (onAgreeClickListener != null) {
                onAgreeClickListener.onAgreeClick(bean.getAnemia());
            }
        } else if (v.getId() == R.id.xpop_updateprompt_cancel_tv) {
            dismiss();
            if (onAgreeClickListener != null) {
                onAgreeClickListener.onCancelClick(bean.isDeorbit());
            }
        }
    }
}